package club.itstudio.IContainer.container;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

@Service
public class ExecContainerCommand {

    ContainerConfig config;

    @Autowired
    public void setContainerConfig(ContainerConfig containerConfig) {
        this.config = containerConfig;
    }

    public void Exec(String commands) throws IOException {
        Process pr = Runtime.getRuntime().exec(config.execPath + " " + commands);
        BufferedReader br = new BufferedReader(new InputStreamReader(pr.getInputStream()));
        while(true){
            //读取响应信息
            String s = br.readLine();
            if(s==null){
                break;
            }
            System.out.println(s);
        }
    }
}
